package com.zbs.framework.swagger.controller;

import com.zbs.framework.swagger.annotations.ApiIgnore;
import com.zbs.framework.swagger.constants.SwaggerApiConstant;
import com.zbs.framework.swagger.controller.params.ApiCheckedParam;
import com.zbs.framework.swagger.entity.ErrorStatus;
import com.zbs.framework.swagger.entity.doc.GroupDoc;
import com.zbs.framework.swagger.entity.eolink.EolinkModel;
import com.zbs.framework.swagger.service.SwaggerApiService;
import com.zbs.framework.swagger.utils.ResultData;
import com.zbs.framework.swagger.utils.ResultUtil;
import com.zbs.framework.swagger.view.TablesView;
import com.zbs.framework.swagger.view.View;
import com.zbs.framework.swagger.view.ViewNew;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ApiIgnore
@RestController
@RequestMapping("/swagger/api")
public class ApiController {

    @Autowired
    private SwaggerApiService swaggerApiService;

    @GetMapping("/getApiList")
    public ResultData getApiList() {
        List<View> apiModel = this.swaggerApiService.getApiModel();
        return ResultUtil.ok(apiModel);
    }

    @GetMapping("/getTablesViewList")
    public ResultData getTablesViewList() {
        List<TablesView> tablesViewList = this.swaggerApiService.getTablesViewList();
        return ResultUtil.ok(tablesViewList);
    }

    @GetMapping("/v2/getApiList")
    public ResultData getApiListV2() {
        Map<String,Object> map = new HashMap<>();
        List<ViewNew> apiModel = this.swaggerApiService.getApiListV2();
        map.put("apiModel",apiModel);
        map.put("idList", SwaggerApiConstant.idList);
        return ResultUtil.ok(map);
    }

    @GetMapping("/getErrorStatusList")
    public ResultData getErrorStatusList() {
        List<ErrorStatus> apiModel = this.swaggerApiService.getErrorStatusList();
        return ResultUtil.ok(apiModel);
    }

    @PostMapping("/exportApi")
    public ResultData exportApi(@RequestBody ApiCheckedParam param) {
        List<GroupDoc> groupDocs = this.swaggerApiService.exportDocApi(param);
        return ResultUtil.ok(groupDocs);
    }

    @PostMapping("/exportEolinkApi")
    public ResultData exportEolinkApi(@RequestBody ApiCheckedParam param) {
        EolinkModel eolinkModel = this.swaggerApiService.exportEolinkApi(param);
        return ResultUtil.ok(eolinkModel);
    }
}
